package com.al.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Query {
	public static void main(String[] args) throws ClassNotFoundException,SQLException {
		//1.加载驱动
		Class.forName("com.mysql.jdbc.Driver");
		//2.建立连接
		String url = "jdbc:mysql://localhost:3306/jdbcdemo?serverTimezone=UTC";
		String user = "root";
		String password = "";
		Connection connection = DriverManager.getConnection(url,user,password);
		//3.创建发送执行sql语句对象，定义sql
		String sql = "select * from users";
		Statement statement = connection.createStatement();
		//4.执行sql
		ResultSet resultSet = statement.executeQuery(sql);
		//5.处理结果
		while(resultSet.next()) {
			System.out.print(resultSet.getInt(1)+"\t\t");
			System.out.print(resultSet.getString(2)+"\t\t");
			System.out.println(resultSet.getString(3));
		}
		//6.关闭资源
		resultSet.close();
		statement.close();
		connection.close();
	}
}
